﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace UnrealDebugger
{
    public abstract class Action
    {
        public void SafeExecute(UnrealDebuggerIDE debugger)
        {
            try
            {
                if (!debugger.IsDisposed)
                {
                    this.Execute(debugger);
                }
            }
            catch (Exception e)
            {
                ExceptionMessageBox msgBox = new ExceptionMessageBox(e);
                msgBox.ShowDialog();
            }
        }

        abstract protected void Execute(UnrealDebuggerIDE debugger);
    }

    public class ShowDllFormAction : Action
    {
        protected override void Execute(UnrealDebuggerIDE debugger)
        {
            UnrealDebuggerIDE.Actions.ShowDllForm();
        }
    }

    public class AddLineToLogAction : Action
    {
        private string _line = "";

        public AddLineToLogAction(string line)
        {
            this._line = line;
        }

        protected override void Execute(UnrealDebuggerIDE debugger)
        {
            UnrealDebuggerIDE.Actions.AddLineToLog(this._line);
        }
    }

    public class CallStackClearAction : Action
    {
        protected override void Execute(UnrealDebuggerIDE debugger)
        {
            UnrealDebuggerIDE.Actions.CallstackClear();
        }
    }

    public class CallStackEntryAction : Action
    {
        private string _entry = "";

        public CallStackEntryAction(string entry)
        {
            this._entry = entry;
        }

        protected override void Execute(UnrealDebuggerIDE debugger)
        {
            UnrealDebuggerIDE.Actions.CallstackEntry(this._entry);
        }
    }

    public class ClearAWatchAction : Action
    {
        private int _type = 0;

        public ClearAWatchAction(int type)
        {
            this._type = type;
        }

        protected override void Execute(UnrealDebuggerIDE debugger)
        {
            UnrealDebuggerIDE.Actions.ClearAWatch(this._type);
        }
    }

    public class LockListAction : Action
    {
        private int _list = 0;

        public LockListAction(int list)
        {
            this._list = list;
        }

        protected override void Execute(UnrealDebuggerIDE debugger)
        {
            UnrealDebuggerIDE.Actions.LockList(this._list);
        }
    }

    public class UnlockListAction : Action
    {
        public class Watch
        {
            public int Type = 0;
            public int Index = 0;
            public int ParentIndex = 0;
            public string VarName = "";
            public string VarValue = "";
        }

        public class WatchList : List<Watch>
        {
        }

        private int _list = 0;
        private WatchList _buffer = null;

        public UnlockListAction(int list, WatchList buffer)
        {
            this._list = list;
            this._buffer = buffer;
        }

        protected override void Execute(UnrealDebuggerIDE debugger)
        {
            UnrealDebuggerIDE.Actions.UnlockList(this._list, this._buffer);
        }
    }

    public class EditorLoadClassAction : Action
    {
        private string _className = "";

        public EditorLoadClassAction(string className)
        {
            this._className = className;
        }

        protected override void Execute(UnrealDebuggerIDE debugger)
        {
            UnrealDebuggerIDE.Actions.LoadClass(this._className);
        }
    }

    public class EditorGotoLineAction : Action
    {
        private int _lineNo = 0;
        private int _highlight = 0;

        public EditorGotoLineAction(int lineNo, int highlight)
        {
            this._lineNo = lineNo;
            this._highlight = highlight;
        }

        protected override void Execute(UnrealDebuggerIDE debugger)
        {
            UnrealDebuggerIDE.Actions.GotoLine(this._lineNo, this._highlight);
        }
    }

    public class ConnectBreakpointAction : Action
    {
        private string _className = "";
        private int _lineNo = 0;

        public ConnectBreakpointAction(string className, int lineNo)
        {
            this._className = className;
            this._lineNo = lineNo;
        }

        protected override void Execute(UnrealDebuggerIDE debugger)
        {
            UnrealDebuggerIDE.Actions.ConnectBreakpoint(this._className, this._lineNo, true);
        }
    }

    public class DisconnectBreakpointAction : Action
    {
        private string _className = "";
        private int _lineNo = 0;

        public DisconnectBreakpointAction(string className, int lineNo)
        {
            this._className = className;
            this._lineNo = lineNo;
        }

        protected override void Execute(UnrealDebuggerIDE debugger)
        {
            UnrealDebuggerIDE.Actions.ConnectBreakpoint(this._className, this._lineNo, false);
        }
    }
}
